﻿<div>
    @foreach( var star in Enumerable.Range(1, 5) )
    {
        <AuthorizeView Policy="@PolicyDefinitions.s_IsEditor">
            <Authorized>
                <i class="@StarStyle(star, true)" @onclick="() => ValueChanged(star)" title="@star stars"/>
            </Authorized>
            <NotAuthorized>
                <i class="@StarStyle(star, false)" title="@star stars"/>
            </NotAuthorized>
        </AuthorizeView>
    }
</div>

@code {

    [Parameter] public int Rating { get; set; }

    [Parameter] public EventCallback<int> RatingChanged { get; set; }

    [Parameter] public bool Editable { get; set; }

    private string StarStyle(int star, bool canEdit)
    {
        return (star <= Rating ? "fas" : "far") + " fa-star damselfly-ratingstar" + (canEdit ? " damselfly-ratingstarmouse" : string.Empty);
    }

    private void ValueChanged(int value)
    {
        Rating = value;
        RatingChanged.InvokeAsync(Rating);
    }

}